from peewee import *
from ..database import database, TABLE_PREFIX


class Currency(database.Model):
    id = CharField(db_column='id', primary_key=True)
    screen_name = CharField(db_column='screen_name', max_length=30, help_text='显示名称')
    logo = CharField(db_column='logo', max_length=200, help_text='显示图标地址', null=True)
    type = CharField(db_column='type', max_length=20, help_text='货币类型', default='normal')
    prefix = CharField(db_column='prefix', max_length=10, help_text='货币前缀')
    suffix = CharField(db_column='suffix', max_length=10, help_text='货币后缀', null=True)
    rate = DecimalField(db_column='rate', decimal_places=2, help_text='相对于主货币比率', null=False, default=1)

    # class Meta:
    #     db_table = '{}_{}'.format(TABLE_PREFIX, 'currencies')

    @classmethod
    def get_main_currency(cls):
        return cls.get(Currency.type == 'main')
